package main

import (
	"github.com/gin-gonic/gin"
	"github.com/DeanThompson/ginpprof"
	"time"
)

func leak() {
	outCh := make(chan int)

	// 每s起100个goroutine，goroutine会阻塞，不释放内存
	tick := time.Tick(time.Second / 100)

	for range tick {
		go alloc(outCh)
	}
}

func alloc(outCh chan<- int) {
	func() {
		outCh <- 0 // 53行
	}()
}

func main() {
	router := gin.Default()

	router.GET("/ping", func(c *gin.Context) {
		go leak()
		c.String(200, "pong")
	})

	ginpprof.Wrap(router)

	router.Run(":8080")
}